<?php
/**
 * Created by PhpStorm.
 * User: iceberg
 * Date: 2018-09-12
 * Time: 6:08
 */

namespace app\index\logic;

use app\model\Admin;
use think\facade\Session;

class IndexLogic
{
    //登录
    public static function login($username, $password)
    {
        $admin = Admin::with('adminRole')->where('user_name', '=', $username)->find();
        if(!$admin)
        {
            return ajaxReturn(false, '帐号错误');
        }

        //$password = password_hash($password, PASSWORD_DEFAULT);
        if(!($admin->password == $password))
        {

            return ajaxReturn(false, '密码错误');
        }

        if($admin->adminRole->act_list == '0' || empty($admin->adminRole->act_list))
        {
            return ajaxReturn(false, '该帐号没有权限');
        }

        Session::set("SIGNIN", true);
        return ajaxReturn(true, '登录成功!');
    }
}